<!DOCTYPE html>












  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222">












<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






















<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=6.4.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.4.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=6.4.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=6.4.0">


  <link rel="mask-icon" href="/images/logo.svg?v=6.4.0" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '6.4.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="在最开始学习Spring Cloud的时候，了解其中有个组件叫做Feign : 可以通过既定规则在本地消费端存留一份服务提供者的接口，这样消费者便可以直接通过这个接口来进行服务消费。 Spring Cloud是一个开源方案的整合体，其中的Feign组件整合的就是已有的一个开源组件Feign。 Feign的中文含义是： 假装！  Inner Peace">
<meta name="keywords" content="HTTP请求">
<meta property="og:type" content="article">
<meta property="og:title" content="使用原生的Feign进行HTTP调用">
<meta property="og:url" content="http://yoursite.com/2018/07/15/pure-feign-hello-world/index.html">
<meta property="og:site_name" content="ThinkMore">
<meta property="og:description" content="在最开始学习Spring Cloud的时候，了解其中有个组件叫做Feign : 可以通过既定规则在本地消费端存留一份服务提供者的接口，这样消费者便可以直接通过这个接口来进行服务消费。 Spring Cloud是一个开源方案的整合体，其中的Feign组件整合的就是已有的一个开源组件Feign。 Feign的中文含义是： 假装！  Inner Peace">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-08-13T12:42:13.366Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="使用原生的Feign进行HTTP调用">
<meta name="twitter:description" content="在最开始学习Spring Cloud的时候，了解其中有个组件叫做Feign : 可以通过既定规则在本地消费端存留一份服务提供者的接口，这样消费者便可以直接通过这个接口来进行服务消费。 Spring Cloud是一个开源方案的整合体，其中的Feign组件整合的就是已有的一个开源组件Feign。 Feign的中文含义是： 假装！  Inner Peace">






  <link rel="canonical" href="http://yoursite.com/2018/07/15/pure-feign-hello-world/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>使用原生的Feign进行HTTP调用 | ThinkMore</title>
  






  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?13172698bcdb7ab00b7d3ec112aae9c1";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">ThinkMore</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <p class="site-subtitle">驽马十驾,功在不舍！</p>
      
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="Toggle navigation bar">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">
    <a href="/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br />Home</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">
    <a href="/archives/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />Archives</a>
  </li>

      
      
    </ul>
  

  
    

  

  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/07/15/pure-feign-hello-world/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="文敦复">
      <meta itemprop="description" content="思考的懒惰是真的懒惰！">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="ThinkMore">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">使用原生的Feign进行HTTP调用
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              

              
                
              

              <time title="Created: 2018-07-15 22:39:30" itemprop="dateCreated datePublished" datetime="2018-07-15T22:39:30+08:00">2018-07-15</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Edited on</span>
                
                <time title="Modified: 2018-08-13 20:42:13" itemprop="dateModified" datetime="2018-08-13T20:42:13+08:00">2018-08-13</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/解决方案/" itemprop="url" rel="index"><span itemprop="name">解决方案</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>在最开始学习<code>Spring Cloud</code>的时候，了解其中有个组件叫做<code>Feign</code> : 可以通过既定规则在本地消费端存留一份服务提供者的接口，这样消费者便可以直接通过这个接口来进行服务消费。</p>
<p><code>Spring Cloud</code>是一个开源方案的整合体，其中的<code>Feign</code>组件整合的就是已有的一个开源组件<code>Feign</code>。</p>
<p><code>Feign</code>的中文含义是： 假装！</p>
<blockquote>
<p>Inner Peace</p>
</blockquote>
<a id="more"></a>
<h1 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h1><p>最近有个项目需要调用第三方提供的HTTP接口，这个项目不是基于<code>Spring Cloud</code>的，所以<code>Spirng Cloud</code>已整合的<code>Feign</code>无法使用。</p>
<p>最开始考虑使用<code>Spring</code>自带的<code>HttpRestemplate</code>但是随着项目编码，发现这种方式使用其他不够方便，每次调用都要写一大堆代码：请求、处理响应、重试这些都需要自己处理，颇多不便。</p>
<p>正好想起了<code>Feign</code>这个开源组件，所以经过一番学习，重新引入了原生的<code>Feign</code>进行HTTP的调用，这里将学的东西做个简单记录。</p>
<h1 id="服务提供者"><a href="#服务提供者" class="headerlink" title="服务提供者"></a>服务提供者</h1><p>先将服务提供者的<code>demo</code>代码附上</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RequestMapping</span>(<span class="string">"/stu"</span>)</span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">StuProvider</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@GetMapping</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> StudentVo <span class="title">getBook</span><span class="params">(@RequestParam(<span class="string">"id"</span>)</span> String id) </span>&#123;</span><br><span class="line">        System.out.println(<span class="string">"id is "</span> + id);</span><br><span class="line">        <span class="keyword">return</span> JMockData.mock(StudentVo.class);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@PostMapping</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> StudentVo <span class="title">postBook</span><span class="params">(@RequestBody StudentVo bookVo)</span> </span>&#123;</span><br><span class="line">        System.out.println(bookVo.toString());</span><br><span class="line">        <span class="keyword">return</span> bookVo;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@PostMapping</span>(<span class="string">"/map"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Map&lt;String, StudentVo&gt; <span class="title">postBook</span><span class="params">(@RequestBody List&lt;StudentVo&gt; bookVo)</span> </span>&#123;</span><br><span class="line">        System.out.println(bookVo.toString());</span><br><span class="line">        <span class="keyword">return</span> JMockData.mock(<span class="keyword">new</span> TypeReference&lt;Map&lt;String, StudentVo&gt;&gt;() &#123;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@PostMapping</span>(<span class="string">"/param"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> StudentVo <span class="title">postParam</span><span class="params">(@RequestParam(<span class="string">"id"</span>)</span> String id) </span>&#123;</span><br><span class="line">        System.out.println(<span class="string">"收到的id为："</span> + id);</span><br><span class="line">        <span class="keyword">return</span> JMockData.mock(StudentVo.class);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="Feign接口"><a href="#Feign接口" class="headerlink" title="Feign接口"></a>Feign接口</h1><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">StuApi</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Headers</span>(<span class="string">"Content-Type: application/json"</span>)</span><br><span class="line">    <span class="meta">@RequestLine</span>(<span class="string">"GET /stu?id=&#123;id&#125;"</span>)</span><br><span class="line">    <span class="function">StudentVo <span class="title">getBook</span><span class="params">(@Param(<span class="string">"id"</span>)</span> String id)</span>;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Headers</span>(&#123;<span class="string">"Content-Type: application/json"</span>, <span class="string">"Accept: application/json"</span>&#125;)</span><br><span class="line">    <span class="meta">@RequestLine</span>(<span class="string">"POST /stu"</span>)</span><br><span class="line">    <span class="function">StudentVo <span class="title">postBook1</span><span class="params">(StudentVo bookVo)</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Headers</span>(&#123;<span class="string">"Content-Type: application/json"</span>, <span class="string">"Accept: application/json"</span>&#125;)</span><br><span class="line">    <span class="meta">@RequestLine</span>(<span class="string">"POST /stu/map"</span>)</span><br><span class="line">    <span class="function">Map&lt;String, StudentVo&gt; <span class="title">postBook2</span><span class="params">(List&lt;StudentVo&gt; bookVo)</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Headers</span>(&#123;<span class="string">"Content-Type: application/json"</span>, <span class="string">"Accept: application/json"</span>&#125;)</span><br><span class="line">    <span class="meta">@RequestLine</span>(<span class="string">"POST /stu/param?id=&#123;id&#125;"</span>)</span><br><span class="line">    <span class="function">StudentVo <span class="title">postParam</span><span class="params">(@Param(<span class="string">"id"</span>)</span> String id)</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="Headers"><a href="#Headers" class="headerlink" title="@Headers"></a>@Headers</h2><p><code>@Headers</code>这个注解需要指明请求的类型和响应类型。</p>
<ol>
<li>如果只有响应的是json,那么如第一个api所示</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Headers</span>(<span class="string">"Content-Type: application/json"</span>)</span><br></pre></td></tr></table></figure>
<ol start="2">
<li>如果请求和相应都是json格式，那么如后面3个所示：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Headers</span>(&#123;<span class="string">"Content-Type: application/json"</span>, <span class="string">"Accept: application/json"</span>&#125;)</span><br></pre></td></tr></table></figure>
<blockquote>
<p>实际测试后发现，只要是@RestController修饰的提供者，不管请求和响应类型，直接采用第二种都可以。</p>
<p>但是如果请求和响应都是json,那么如果不些@Headers这个注解，肯定报错。比如后续的2 3 4这3个API.</p>
</blockquote>
<h2 id="RequestLine"><a href="#RequestLine" class="headerlink" title="@RequestLine"></a>@RequestLine</h2><p>通过<code>@RequestLine</code>来标明当前接口的类型。</p>
<p>比如如下API标明的就是<code>Get</code>请求</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RequestLine</span>(<span class="string">"GET /stu?id=&#123;id&#125;"</span>)</span><br></pre></td></tr></table></figure>
<p><code>Post</code>的类似</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RequestLine</span>(<span class="string">"POST /stu"</span>)</span><br></pre></td></tr></table></figure>
<h1 id="使用方法"><a href="#使用方法" class="headerlink" title="使用方法"></a>使用方法</h1><p>构建了上述接口后，那么如何使用了，Feign提供了基于<code>Builder</code>模式的构造</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">StuApi api = Feign.builder() <span class="comment">//创建feign的构建者</span></span><br><span class="line">	.encoder(<span class="keyword">new</span> JacksonEncoder())  <span class="comment">//JSON编码</span></span><br><span class="line">	.decoder(<span class="keyword">new</span> JacksonDecoder()) <span class="comment">//JSON解码</span></span><br><span class="line">	.options(<span class="keyword">new</span> Request.Options(<span class="number">1000</span>, <span class="number">3500</span>))  <span class="comment">//设置超时</span></span><br><span class="line">	.retryer(<span class="keyword">new</span> Retryer.Default(<span class="number">5000</span>, <span class="number">5000</span>, <span class="number">3</span>))  <span class="comment">//设置重试</span></span><br><span class="line">	.target(StuApi.class, <span class="string">"http://127.0.0.1:8080"</span>); <span class="comment">//设置代理的接口以及目标地址</span></span><br></pre></td></tr></table></figure>
<p>然后可以通过<code>api.xxx</code>进行服务调用。</p>
<p>这里请不要忘记引入相关的引用，相关的<code>pom.xml</code></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--feign的客户端--&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.github.openfeign<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>feign-httpclient<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">version</span>&gt;</span>9.7.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.github.openfeign<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>feign-core<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">version</span>&gt;</span>9.7.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="comment">&lt;!--因为使用的是jackson 序列化，所以引入此包--&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.github.openfeign<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>feign-jackson<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">version</span>&gt;</span>9.7.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="comment">&lt;!--客户端使用的okhttp所以引入此包--&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.github.openfeign<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>feign-okhttp<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">version</span>&gt;</span>9.7.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.squareup.okhttp3<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>okhttp<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">version</span>&gt;</span>3.10.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>其他相关的引用可以从此处查看：</p>
<p><a href="http://mvnrepository.com/artifact/io.github.openfeign" target="_blank" rel="noopener">http://mvnrepository.com/artifact/io.github.openfeign</a></p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>通过<code>Feign</code>的方式进行<code>HTTP</code>调用真心很方便，如果有涉及到需要调用第三方提供HTTP接口的时候，不妨考虑下<code>Feign</code>。</p>
<blockquote>
<p>您有任何建议和意见，请Email联系: <a href="mailto:hicode_club@163.com" target="_blank" rel="noopener">hicode_club@163.com</a></p>
<p>转载请保留出处 <a href="http://www.hicode.club" target="_blank" rel="noopener">HiCode 俱乐部</a></p>
</blockquote>

      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/07/12/udp-req-res/" rel="next" title="基于TCP/UDP的请求响应模型设计">
                <i class="fa fa-chevron-left"></i> 基于TCP/UDP的请求响应模型设计
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/07/26/cache-think-1/" rel="prev" title="缓存更新策略（一）">
                缓存更新策略（一） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">文敦复</p>
              <p class="site-description motion-element" itemprop="description">思考的懒惰是真的懒惰！</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">39</span>
                    <span class="site-state-item-name">posts</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">37</span>
                    <span class="site-state-item-name">categories</span>
                  
                </div>
              

              
            </nav>
          

          

          

          
          

          
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#背景"><span class="nav-number">1.</span> <span class="nav-text">背景</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#服务提供者"><span class="nav-number">2.</span> <span class="nav-text">服务提供者</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Feign接口"><span class="nav-number">3.</span> <span class="nav-text">Feign接口</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Headers"><span class="nav-number">3.1.</span> <span class="nav-text">@Headers</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#RequestLine"><span class="nav-number">3.2.</span> <span class="nav-text">@RequestLine</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#使用方法"><span class="nav-number">4.</span> <span class="nav-text">使用方法</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#总结"><span class="nav-number">5.</span> <span class="nav-text">总结</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">文敦复</span>

  

  
</div>




  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> v3.7.1</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme – <a class="theme-link" target="_blank" href="https://theme-next.org">NexT.Muse</a> v6.4.0</div>




        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    
	
    

    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.4.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.4.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.4.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.4.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.4.0"></script>



  



  










  





  

  

  

  

  
  

  

  

  

  

  

</body>
</html>
